package org.xxx.epms.result.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xxx.epms.result.mapper.GridCityMapper;
import org.xxx.epms.result.models.GridCity;
import org.xxx.epms.result.service.GridCityService;


import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lb
 * @since 2024-06-08
 */
@Service
public class GridCityServiceImpl extends ServiceImpl<GridCityMapper, GridCity> implements GridCityService {
    @Autowired
    private GridCityMapper gridCityMapper;

    @Override
    public GridCity getGridCityById(Integer cityId) {
        QueryWrapper<GridCity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("city_id", cityId);
        GridCity gridCity = gridCityMapper.selectOne(queryWrapper);
        return gridCity;
    }

    @Override
    public List<GridCity> getCityByProvinceId(Integer provinceId) {
        QueryWrapper<GridCity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("province_id", provinceId);
        List<GridCity> gridCityList = gridCityMapper.selectList(queryWrapper);
        return gridCityList;
    }

    @Override
    public void addGridCity(GridCity gridCity) {
        if(getGridCityById(gridCity.getCityId()) == null){
            gridCityMapper.insert(gridCity);
        }
    }
}
